odhcpd: remove OAF_BOUND
authorDavid Härdeman <[email protected]>
Thu, 27 Nov 2025 17:02:11 +0000 (18:02 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Sun, 30 Nov 2025 16:00:25 +0000 (17:00 +0100)
Replace the OAF_BOUND flag with a simple boolean.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/331
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv4.c
src/dhcpv6-ia.c
src/odhcpd.h
src/statefiles.c
src/ubus.c

index ab1a762d7c00029b9cb14ca405ca03258a6c50e0..5073d97ae595a8b6f2fdf5ffea7a73b6b6b9c091 100644 (file)
@@ -568,7 +568,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
                lease = NULL;
        }
 
-       if (lease && (lease->flags & OAF_BOUND) && lease->fr_ip) {
+       if (lease && lease->bound && lease->fr_ip) {
                *fr_serverid = lease->fr_ip->addr.addr.in.s_addr;
                dhcpv4_fr_stop(lease);
        }
@@ -587,7 +587,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
                if (!lease)
                        return NULL;
 
-               lease->flags &= ~OAF_BOUND;
+               lease->bound = false;
 
                if (!lease->lease_cfg || lease->lease_cfg->ipv4.s_addr != lease->ipv4.s_addr) {
                        memset(lease->hwaddr, 0, sizeof(lease->hwaddr));
@@ -655,7 +655,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
                        *req_leasetime = max_leasetime;
 
                if (req_msg == DHCPV4_MSG_DISCOVER) {
-                       lease->flags &= ~OAF_BOUND;
+                       lease->bound = false;
                        *reply_incl_fr = req_accept_fr;
                        lease->valid_until = now;
                        break;
@@ -672,14 +672,14 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
                }
 
                *reply_incl_fr = false;
-               if (!(lease->flags & OAF_BOUND)) {
+               if (!lease->bound) {
                        /* This is the client's first request for the address */
                        if (req_accept_fr) {
                                lease->accept_fr_nonce = true;
                                *reply_incl_fr = true;
                                odhcpd_urandom(lease->key, sizeof(lease->key));
                        }
-                       lease->flags |= OAF_BOUND;
+                       lease->bound = true;
                }
 
                if (*req_leasetime == UINT32_MAX)
@@ -1601,7 +1601,7 @@ static void dhcpv4_addrlist_change(struct interface *iface)
        }
 
        avl_for_each_element(&iface->dhcpv4_leases, lease, iface_avl) {
-               if ((lease->flags & OAF_BOUND) && lease->fr_ip && !lease->fr_cnt) {
+               if (lease->bound && lease->fr_ip && !lease->fr_cnt) {
                        if (lease->accept_fr_nonce || iface->dhcpv4_forcereconf)
                                dhcpv4_fr_rand_delay(lease);
                        else
index 6f3852d2c924621145e9255bbf8e7c4443558ccf..f227ad60c731f46e22032d53547bdbe1e22191e5 100644 (file)
@@ -63,7 +63,7 @@ void dhcpv6_free_lease(struct dhcpv6_lease *a)
        list_del(&a->head);
        list_del(&a->lease_cfg_list);
 
-       if ((a->flags & OAF_BOUND) && (a->flags & OAF_DHCPV6_PD))
+       if (a->bound && (a->flags & OAF_DHCPV6_PD))
                apply_lease(a, false);
 
        if (a->fr_cnt)
@@ -349,7 +349,7 @@ static bool assign_pd(struct interface *iface, struct dhcpv6_lease *assign)
                        if (assign->assigned_subnet_id >= current && assign->assigned_subnet_id + asize < c->assigned_subnet_id) {
                                list_add_tail(&assign->head, &c->head);
 
-                               if (assign->flags & OAF_BOUND)
+                               if (assign->bound)
                                        apply_lease(assign, true);
 
                                return true;
@@ -371,7 +371,7 @@ static bool assign_pd(struct interface *iface, struct dhcpv6_lease *assign)
                        assign->assigned_subnet_id = current;
                        list_add_tail(&assign->head, &c->head);
 
-                       if (assign->flags & OAF_BOUND)
+                       if (assign->bound)
                                apply_lease(assign, true);
 
                        return true;
@@ -466,7 +466,7 @@ static void handle_addrlist_change(struct netevent_handler_info *info)
 
        list_for_each_entry(c, &iface->ia_assignments, head) {
                if ((c->flags & OAF_DHCPV6_PD) && !(iface->ra_flags & ND_RA_FLAG_MANAGED)
-                               && (c->flags & OAF_BOUND))
+                   && (c->bound))
                        __apply_lease(c, info->addrs_old.addrs,
                                        info->addrs_old.len, false);
        }
@@ -481,7 +481,7 @@ static void handle_addrlist_change(struct netevent_handler_info *info)
 
                if (c->assigned_subnet_id >= border->assigned_subnet_id)
                        list_move(&c->head, &reassign);
-               else if (c->flags & OAF_BOUND)
+               else if (c->bound)
                        apply_lease(c, true);
 
                if (c->accept_fr_nonce && c->fr_cnt == 0) {
@@ -1117,7 +1117,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac
                        a = c;
 
                        /* Reset state */
-                       if (a->flags & OAF_BOUND)
+                       if (a->bound)
                                apply_lease(a, false);
 
                        stop_reconf(a);
@@ -1228,7 +1228,7 @@ proceed:
 
                        /* Was only a solicitation: mark binding for removal in 60 seconds */
                        if (assigned && hdr->msg_type == DHCPV6_MSG_SOLICIT && !rapid_commit) {
-                               a->flags &= ~OAF_BOUND;
+                               a->bound = false;
                                a->valid_until = now + 60;
 
                        } else if (assigned &&
@@ -1245,7 +1245,7 @@ proceed:
                                        }
                                }
                                a->accept_fr_nonce = accept_reconf;
-                               a->flags |= OAF_BOUND;
+                               a->bound = true;
                                apply_lease(a, true);
                        } else if (!assigned) {
                                /* Cleanup failed assignment */
@@ -1263,13 +1263,13 @@ proceed:
                                        hdr->msg_type == DHCPV6_MSG_REBIND) {
                                ia_response_len = build_ia(buf, buflen, status, ia, a, iface, false);
                                if (a) {
-                                       a->flags |= OAF_BOUND;
+                                       a->bound = true;
                                        apply_lease(a, true);
                                }
                        } else if (hdr->msg_type == DHCPV6_MSG_RELEASE) {
                                a->valid_until = now - 1;
                        } else if ((a->flags & OAF_DHCPV6_NA) && hdr->msg_type == DHCPV6_MSG_DECLINE) {
-                               a->flags &= ~OAF_BOUND;
+                               a->bound = false;
 
                                if (!a->lease_cfg || a->lease_cfg->hostid != a->assigned_host_id) {
                                        memset(a->duid, 0, a->duid_len);
@@ -1283,7 +1283,7 @@ proceed:
                                break;
                        }
 
-                       if (!ia_addr_present || !a || !(a->flags & OAF_BOUND)) {
+                       if (!ia_addr_present || !a || !a->bound) {
                                response_len = 0;
                                goto out;
                        }
index 3fb3acc899ebbbec50c4b445799c92f653e94d89..1ce2452ce6f46b491a3d49f2c6e04baaa10348fc 100644 (file)
@@ -190,9 +190,8 @@ enum odhcpd_mode {
 
 
 enum odhcpd_assignment_flags {
-       OAF_BOUND               = (1 << 0),
-       OAF_DHCPV6_NA           = (1 << 1),
-       OAF_DHCPV6_PD           = (1 << 2),
+       OAF_DHCPV6_NA           = (1 << 0),
+       OAF_DHCPV6_PD           = (1 << 1),
 };
 
 /* 2-byte type + 128-byte DUID, RFC8415, §11.1 */
@@ -254,7 +253,7 @@ struct dhcpv4_lease {
        struct lease_cfg *lease_cfg;            // host lease cfg, nullable
 
        struct in_addr ipv4;                    // client IPv4 address
-       unsigned int flags;                     // OAF_*
+       bool bound;                             // the lease has been accepted by the client
        time_t valid_until;                     // CLOCK_MONOTONIC time, 0 = inf
        char *hostname;                         // client hostname
        bool hostname_valid;                    // is the hostname one or more valid DNS labels?
@@ -298,6 +297,7 @@ struct dhcpv6_lease {
        uint8_t length; // length == 128 -> IA_NA, length <= 64 -> IA_PD
 
        unsigned int flags;
+       bool bound;                             // the lease has been accepted by the client
        uint32_t leasetime;
        char *hostname;
        bool hostname_valid;                    // is the hostname one or more valid DNS labels?
index 20664f6d26636b719a0239ea2733b5385bbaf5cd..d0ccef5557bd20559073f7b70f6089a5c6298da2 100644 (file)
@@ -122,7 +122,7 @@ static void statefiles_write_hosts(time_t now)
                        struct dhcpv6_lease *lease;
 
                        list_for_each_entry(lease, &ctxt.iface->ia_assignments, head) {
-                               if (!(lease->flags & OAF_BOUND))
+                               if (!lease->bound)
                                        continue;
 
                                if (!INFINITE_VALID(lease->valid_until) && lease->valid_until <= now)
@@ -137,7 +137,7 @@ static void statefiles_write_hosts(time_t now)
                        struct dhcpv4_lease *lease;
 
                        avl_for_each_element(&ctxt.iface->dhcpv4_leases, lease, iface_avl) {
-                               if (!(lease->flags & OAF_BOUND))
+                               if (!lease->bound)
                                        continue;
 
                                if (!INFINITE_VALID(lease->valid_until) && lease->valid_until <= now)
@@ -273,7 +273,7 @@ static bool statefiles_write_state(time_t now)
                        struct dhcpv6_lease *lease;
 
                        list_for_each_entry(lease, &ctxt.iface->ia_assignments, head) {
-                               if (!(lease->flags & OAF_BOUND))
+                               if (!lease->bound)
                                        continue;
 
                                if (!INFINITE_VALID(lease->valid_until) && lease->valid_until <= now)
@@ -287,7 +287,7 @@ static bool statefiles_write_state(time_t now)
                        struct dhcpv4_lease *lease;
 
                        avl_for_each_element(&ctxt.iface->dhcpv4_leases, lease, iface_avl) {
-                               if (!(lease->flags & OAF_BOUND))
+                               if (!lease->bound)
                                        continue;
 
                                if (!INFINITE_VALID(lease->valid_until) && lease->valid_until <= now)
index 5cbd09d2fae268ea02bc37312cdef3a31f16aa97..413bbfc2ccc64408406ff00761c7598108670e92 100644 (file)
@@ -59,7 +59,7 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _o_unused struct ubus_
                        blobmsg_add_u8(&b, "accept-reconf", c->accept_fr_nonce);
 
                        m = blobmsg_open_array(&b, "flags");
-                       if (c->flags & OAF_BOUND)
+                       if (c->bound)
                                blobmsg_add_string(&b, NULL, "bound");
 
                        if (c->lease_cfg)
@@ -151,7 +151,7 @@ static int handle_dhcpv6_leases(_o_unused struct ubus_context *ctx, _o_unused st
                                blobmsg_add_u16(&b, "assigned", a->assigned_subnet_id);
 
                        m = blobmsg_open_array(&b, "flags");
-                       if (a->flags & OAF_BOUND)
+                       if (a->bound)
                                blobmsg_add_string(&b, NULL, "bound");
 
                        if (a->lease_cfg)